package com.fileshare.web.dto.Vo;

import com.fileshare.web.entity.Article;
import com.fileshare.web.entity.Category;
import com.fileshare.web.entity.Label;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ArticleVo {
    private Integer id;
    private String title;
    private String articleSeq;
    private String summary;
    private String content;
    private Boolean hasPayment;
    private Boolean hasResource;
    private Boolean hasLimit;
    private Integer views;
    private Integer likes;
    private Integer dislikes;
    private Integer commentCount;
    private String status;
    private Boolean allowComment;
    private Boolean allowLikes;
    private Category category;
    private String coverImage;
    private String documentType;
    private Date createAt;
    private String createBy;
    private UserVo user;
    private List<Label> labels;
    List<ArticleVo> relatedArticles;

    public static ArticleVo fromEntity(Article article) {
        ArticleVo articleVo = new ArticleVo();
        BeanUtils.copyProperties(article, articleVo);
        return articleVo;
    }

    public static List<ArticleVo> fromEntities(List<Article> articles) {
        return articles.stream().map(ArticleVo::fromEntity).collect(Collectors.toList());
    }
}
